package com.mopon.springbootmvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

	@GetMapping("/index")
	public String index() {
		return "index";
	}
	
	@PostMapping("/login")
	public String login(@RequestParam("username")String username, @RequestParam("password")String password) {
		if (username.equals(password)) {
			return "ok";
		}
		return "fail";
	}
	
	@GetMapping("/login")
	public String loginIndex(Model model) {
		model.addAttribute("username", "root");
		return "login";
	}
	
	@GetMapping("/admin")
	public String admin(Model model) {
		model.addAttribute("username", "root");
		return "admin/index";
	}
}
